define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            Fast.config.openArea = ['95%','95%'];
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'course/classess_config/index' + location.search,
                    add_url: 'course/classess_config/add',
                    edit_url: 'course/classess_config/edit',
                    del_url: 'course/classess_config/del',
                    multi_url: 'course/classess_config/multi',
                    import_url: 'course/classess_config/import',
                    table: 'course_classess_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList:Config.typeList, formatter: Table.api.formatter.label},
                        {field: 'select_count', title: __('Select_count'), operate: false},

                        // {field: 'tip', title: __('Tip'), operate: false},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'switch', title: __('Switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            //因为日期选择框不会触发change事件，导致无法刷新textarea，所以加上判断

            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                //因为日期选择框不会触发change事件，导致无法刷新textarea，所以加上判断
                $(document).on("dp.change", ".datetimepicker", function () {
                    $(this).parent().prev().find("input").trigger("change");
                });
                $(document).on("fa.event.appendfieldlist", ".btn-append", function(){
                    Form.events.datetimepicker();
                });
                // $("#test").click(function (){
                //     // alert(11);
                //     $("#aaa").val("[{\"start\":\"10:56:15\",\"end\":\"10:56:16\",\"count\":\"4111\"}]");
                //     Form.events.fieldlist("form");
                //     return ;
                // });
            }
        }
    };
    return Controller;
});
